#ifndef ToolButtonPopupShell_h
#define ToolButtonPopupShell_h

#include <QToolButton>
#include <QJsonObject>
#include <QJsonArray>
#include <QVariant>

class ToolButtonPopupShell : public QObject
{
    Q_OBJECT
public:
    ToolButtonPopupShell(QToolButton *toolButton);
    ToolButtonPopupShell();
    ~ToolButtonPopupShell();

    void shell(QToolButton *toolButton);

    /**
     * @brief setData
     * @param object
     *
     * checkable - 是否可选
     * exclusive - 是否为互斥，该值设置true后，将忽略checkable和单个action的checkable，并将所有action设置为可选择
     * items:[item]
     */
    void setData(const QJsonObject &object);

    /**
     * @brief addItems
     * @param array
     *
     * userInfo - 其他用户信息
     *
     * type - 类型
     * action类型
     *  text - 标题
     *  icon - 图标
     *  name - 标识
     *  checkable - 是否可选
     *  checked - 是否选中
     */
    void addItems(const QJsonArray &array);
    void addActions(const QJsonArray &array);
    void addAction(const QJsonObject &object);

    void updateUserInfo(const QString &name, const QString &key, const QVariant &value);
    void resetUserInfo(const QString &name, const QVariant &userInfo);
    QVariant getUserInfo(const QString &name);

signals:
    void sigClicked(QString name, bool checked, QVariant userInfo);

private:
    QMenu* menu();

private slots:
    void onTriggered(QAction *action);

private:
    QToolButton *_target;
};

#endif ToolButtonPopupShell_h
